package org.kimoji.global.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.kimoji.entity.Category;
import org.kimoji.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Repository;


@Repository
public class GlobalDAO {

	@Autowired
	private SqlSession sqlSession;
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	
	private static final String CATEGORY = "category";
	
	public List<Category> getCategories(){
		return sqlSession.selectList("GlobalMapper.getCategories");
	}
	
	public void cacheCategories(List<Category> categories){
		redisTemplate.opsForValue().set(CATEGORY, categories);
	}
	
	public List<Category> getCacheCategories(){
		return (List<Category>)redisTemplate.opsForValue().get(CATEGORY);
	}
	
}
